package com.xiaoxiang.mall.consumer;

import com.xiaoxiang.common.api.PayResult;
import com.xiaoxiang.mall.entity.OrderInfo;
import com.xiaoxiang.mall.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author: haha
 * @date: 2022/5/5 18:58
 */
@Component
@RocketMQMessageListener(topic = "pay_result",consumerGroup = "xiaoxiang-mall")
@Slf4j
public class PayResultHandler implements RocketMQListener<PayResult> {

    @Resource
    private OrderInfoService orderInfoService;

    @Override
    public void onMessage(PayResult result) {
        OrderInfo orderInfo = OrderInfo.builder()
                .payOrderId(result.getOrderId())
                .finishTime(new Date())
                .state("支付成功")
                .build();
        orderInfoService.updateByPayOrderId(orderInfo);
    }
}
